<?php
namespace Home\Controller;

use Util\AccessController;

class ArticlesController extends AccessController {

    /*
     * 根据id获取文章
     * GET
     * ID 文章id
     */
    public function GetArticles_ID() {
        $LS = Service('Articles', 'articles');
        $data = $LS->find(array('ID' => $_GET['ID']));
        $LS1 = Service('Articles', 'banner');
        $files1 = 'banner_img';
        $data1 = $LS1->query(array('yb_id' => $_GET['ID']), null, $files1);
        $data['pics'] = $data1;
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }

    /*
  * 点赞/阅读/收藏 +1
  * POST
  *参数ID 文章id
  *参数TYPE （1点赞 2阅读 3 收藏）
  */
    public function ArticlesAddNum() {
        $LS = Service('Articles', 'articles');
        $adata = $this->find(array('ID' => $_POST['ID']));
        if ($_POST['TYPE'] == 1) {
            $save['DZ_NUM'] = $adata['DZ_NUM'] + 1;
        }
        if ($_POST['TYPE'] == 2) {
            $save['YD_NUM'] = $adata['YD_NUM'] + 1;
        }
        if ($_POST['TYPE'] == 3) {
            $save['SC_NUM'] = $adata['SC_NUM'] + 1;
        }
        $data = $LS->update(array('ID' => $_POST['ID']), $save);
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }


}